package com.yida.common.security.properties;

import org.springframework.beans.factory.annotation.Autowired;

import com.yida.common.core.constant.CacheConstants;
import com.yida.common.redis.service.RedisService;

public class CoexistProperties {

	@Autowired
	private RedisService redisService;

	// 是否多端登录校验开关
	private final String coexistEnabled = "sys.coexist.enabled";

	/**
	 * 开关
	 */
	private Boolean enabled;

	public Boolean getEnabled() {
		enabled = false;
		String redisEnabled = redisService.getCacheObject(getCacheKey(coexistEnabled));
		if (redisEnabled == null || redisEnabled.length() == 0) {
			enabled = false;
		}
		if ("true".equals(redisEnabled)) {
			enabled = true;
		}
		return enabled;
	}

	public void setEnabled(Boolean enabled) {
		this.enabled = enabled;
	}

	/**
	 * 设置cache key
	 * 
	 * @param configKey 参数键
	 * @return 缓存键key
	 */
	public String getCacheKey(String configKey) {
		return CacheConstants.SYS_CONFIG_KEY + configKey;
	}

}
